package huoye.shops.huoye.operation.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import huoye.shops.base.BaseActivity;
import huoye.shops.base.PullToRefreshFragment;
import huoye.shops.huoye.operation.activity.MineSetEventDetailsActivity;
import huoye.shops.huoye.operation.activity.SharePondActivity;
import huoye.shops.huoye.operation.adapter.ManageEventAdapter;
import huoye.shops.huoye.operation.adapter.MineSetEventAdapter;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.operation.presenter.ManageEventPresenter;
import huoye.shops.huoye.operation.presenter.MineSetEventPresenter;
import huoye.shops.huoye.operation.view.IManageEventRefreshView;
import huoye.shops.huoye.operation.view.IMineSetEventRefreshView;


/**
 * 2018 - 08 - 12 .
 */
public class MineSetEventFragment extends PullToRefreshFragment<ManageEventData> implements IMineSetEventRefreshView {

    public static final int TYPE_MINE_SET_EVENT_DNS = 0; //未开始
    public static final int TYPE_MINE_SET_EVENT_START = 1; //进行中
    public static final int TYPE_MINE_SET_EVENT_END = 2; //已结束


    private int mState;
    private MineSetEventPresenter mMineSetEventPresenter;

    @Override
    public RecyclerViewAdapter createAdapter() {
        Bundle bundle = getArguments();
        mState = bundle.getInt(BaseActivity.EXTRAS_KEY_DATA);
        MineSetEventAdapter adapter = new MineSetEventAdapter(getActivity());
        adapter.setOnMineSetEventListener(new MineSetEventAdapter.OnMineSetEventListener() {
           @Override
           public void onDetailsClick(ManageEventData data) {
                startActivity(MineSetEventDetailsActivity.class,data);
           }
        });
        return adapter;
    }



    @Override
    public void onResume() {
        super.onResume();
        if(mMineSetEventPresenter != null ){
            query();
        }
    }

    @Override
    protected void initView(View view, @Nullable Bundle bundle) {
        super.initView(view, bundle);
        mMineSetEventPresenter = new MineSetEventPresenter();
        mMineSetEventPresenter.addTaskListener(this);
        mMineSetEventPresenter.onStart();
        query();
    }


    @Override
    public void query(Paging paging) {
        super.query(paging);
        mMineSetEventPresenter.getEventList(mState,1,paging);
    }


    public static MineSetEventFragment getInstan(int type) {
        MineSetEventFragment fragment = new MineSetEventFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BaseActivity.EXTRAS_KEY_DATA, type);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onItemClick(ManageEventData manageEventData, int i, View view) {

    }
}
